package main

import (
	"flag"
	"io"
	"log"
	"net"
)

var (
	host = flag.String("host", "", "host")
	port = flag.String("port", "port", "port")
)

func main(){
	flag.Parse();
	//指针字符串的拼接
	l, err := net.Listen("tcp", *host + ":" + *port)
	if err != nil {
		log.Fatalln("Error listening:", err)
	}
	defer l.Close()

	for{
		conn, err := l.Accept()
		if err != nil {
			log.Println("accept error:", err)
			continue;
		}
		go dispatch(conn)
	}
}

func dispatch(conn net.Conn){
	defer conn.Close()
	for{
		io.Copy(conn, conn)
	}
}